// 2025/4/4
// https://leetcode.cn/problems/zigzag-conversion/description/
// Z字形变换

class Solution {
    public:
        string convert(string s, int numRows) {
            vector<string> strs(numRows);
            if(numRows <= 1) return s;
            int group = (numRows - 1) * 2, n = s.size();
            for(int i = 0; i < n; i++)
            {
                int pos = i % group;
                int k = group >> 1;
                if(pos > k)
                {
                    pos = k - (pos - k);
                }
                strs[pos] += s[i];
            }
            string ans;
            for(auto& str : strs)
                ans += str;
            return ans;
        }
    };